package com.nf.practice.jsontest;

import com.alibaba.fastjson.JSONObject;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.TypeRef;
import com.nf.practice.utils.JsonPathUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class JsonConvert {

    @Test
    public void test() throws IOException {
        File file = new File("E:/jsonbaowen");
        String respJson = FileUtils.readFileToString(file);
        System.out.println(respJson);
//
//        JSONObject data = JSONObject.parseObject(JSONObject.parseObject(respJson).get("data").toString());
//        System.out.println(data);
//        JSONObject jsonObject = JSONObject.parseObject(data.getString("json"));
//        System.out.println(jsonObject);
//        List<String> mobiles = JsonPath.read(jsonObject, "$..['jbo.icr.html.ICR_PIM_TELNUMBER'][*].MOBILE");
//        List<String> mailPhones = JsonPath.read(jsonObject, "$..['jbo.icr.html.ICR_PMM_MARRIAGE'][*].TELEPHONENO");
//        System.out.println(mobiles);
//        System.out.println(mailPhones);

        JSONObject resp = JSONObject.parseObject(respJson);
        if(!"000000".equals(resp.getString("code"))) {
            System.out.println("获取RH04征信报文失败：" + resp.getString("code"));
        }

        JSONObject data = resp.getJSONObject("data");
        // 获取客户征信手机号和客户配偶征信手机号
        List<String> mobiles = JsonPath.read(data.getString("json"), "$..['jbo.icr.html.ICR_PIM_TELNUMBER'][*].MOBILE");
        List<String> telePhoneNos = JsonPath.read(data.getString("json"), "$..['jbo.icr.html.ICR_PMM_MARRIAGE'][*].TELEPHONENO");
        System.out.println(mobiles);
        System.out.println(telePhoneNos);
    }

}
